package com.bestdreamer.threadbasic;

public class HasSelfPrivateNum {

    private int num = 0;

    synchronized public void addI(String username){
//    public void addI(String username){
        try{
            // 方法中的变量不存在非线程安全问题，永远都是线程安全的
//            int num = 0;
            if(username.equals("a")){
                num = 100;
                System.out.println("a set over!");
                Thread.sleep(2000);
            }else{
                num = 200;
                System.out.println("b set over!");
            }
            System.out.println(username + "num=" + num);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }
}
